﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Fore : MonoBehaviour
{
    public Levels level;
    public enum Action
    {
        MouseOver,
        Hit
    }
    [System.Serializable]
    public struct Contents
    {
        public Action action;
        [System.Serializable]
        public class Actions
        {
            public string name, content;
        }
        public List<Actions> actions;
    }
    public List<Contents> contents;

    private void OnTriggerEnter2D(Collider2D collision)
    {
        foreach(var item in contents)
        {
            if (item.action == Action.Hit)
            {
                foreach(var content in item.actions)
                {
                    if (content.name == collision.gameObject.name)
                    {
                        level.OnHit(content.content);
                        return;
                    }
                }
            }
        }
    }
    private void OnMouseEnter()
    {
        foreach (var item in contents)
        {
            if (item.action == Action.MouseOver)
            {
                foreach (var content in item.actions)
                {
                    if (content.name == gameObject.name)
                    {
                        level.MouseOver(content.content);
                        return;
                    }
                }
            }
        }
    }
    private void OnMouseExit()
    {
        level.MouseExit();
    }
}
